package com.plus.config;

import lombok.extern.slf4j.Slf4j;

/**
 * @program: springboot-caffeineCache
 * @ClassName DynamicDataSourceContextHolder
 * @description:动态数据源切换上下文
 * @author: 黄涛
 * @create: 2023-11-22 14:02
 * @Version 1.0
 **/
@Slf4j
public class DynamicDataSourceContextHolder {

    private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();

    public static void setDataSourceType(String dataSourceType) {
        log.info("切换到{}数据库",dataSourceType);
        CONTEXT_HOLDER.set(dataSourceType);
    }

    public static String getDataSourceType() {
        return CONTEXT_HOLDER.get();
    }

    public static void clearDataSourceType() {
        CONTEXT_HOLDER.remove();
    }
}
